package com.ruoyi.business.base.controller;

import com.ruoyi.business.base.domain.AssetCard;
import com.ruoyi.business.base.service.IAssetCardService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产档案Controller
 *
 * @author lcy
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/base/assetCard")
@Api(tags = "资产档案相关接口")
public class AssetCardController extends BaseController {

    @Autowired
    private IAssetCardService assetCardService;

    /**
     * 查询资产档案列表
     */
    @RequiresPermissions("base:assetCard:list")
    @GetMapping("/list")
    @ApiOperation("查询资产档案列表")
    @Log(value = "查询资产档案列表")
    public TableDataInfo list(AssetCard assetCard) {
        startPage();
        List<AssetCard> list = assetCardService.selectAssetCardList(assetCard);
        return getDataTable(list);
    }

    /**
     * 导出资产档案列表
     */
    @RequiresPermissions("base:assetCard:export")
    @Log(title = "资产档案", businessType = BusinessType.EXPORT,value = "导出资产档案列表")
    @PostMapping("/export")
    @ApiOperation("导出资产档案列表")
    public void export(HttpServletResponse response, AssetCard assetCard) {
        List<AssetCard> list = assetCardService.selectAssetCardList(assetCard);
        ExcelUtil<AssetCard> util = new ExcelUtil<AssetCard>(AssetCard.class);
        util.exportExcel(response, list, "资产档案数据");
    }

    /**
     * 获取资产档案详细信息
     */
    @RequiresPermissions("base:assetCard:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取资产档案详细信息")
    @Log(value = "获取资产档案详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(assetCardService.selectAssetCardById(id));
    }

    /**
     * 新增资产档案
     */
    @RequiresPermissions("base:assetCard:add")
    @Log(title = "资产档案", businessType = BusinessType.INSERT,value = "新增资产档案")
    @PostMapping("/insert")
    @ApiOperation("新增资产档案")
    public AjaxResult add(@RequestBody AssetCard assetCard) {
        return toAjax(assetCardService.insertAssetCard(assetCard));
    }

    /**
     * 修改资产档案
     */
    @RequiresPermissions("base:assetCard:edit")
    @Log(title = "资产档案", businessType = BusinessType.UPDATE,value = "修改资产档案")
    @PutMapping("/update")
    @ApiOperation("修改资产档案")
    public AjaxResult edit(@RequestBody AssetCard assetCard) {
        return toAjax(assetCardService.updateAssetCard(assetCard));
    }

    /**
     * 删除资产档案
     */
    @RequiresPermissions("base:assetCard:remove")
    @Log(title = "资产档案", businessType = BusinessType.DELETE,value = "删除资产档案")
	@DeleteMapping("/delete/{ids}")
    @ApiOperation("删除资产档案")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(assetCardService.deleteAssetCardByIds(ids));
    }
}
